#include<iostream>
#include<string>
#include<vector>
using namespace std;

class Solution {
public:
    vector<int> partitionLabels(string S) {
        int index[26] = {0};
        for (int i = 0; i < S.size(); i++) {
            index[S[i] - 'a'] = i;
        }
        int end = 0;
        int start = 0;
        vector<int> T;
        for (int i = 0; i < S.size(); i++) {
            end = max(index[S[i]-'a'], end);
            if (i == end) {
                T.push_back(end + 1-start);
                start = end + 1;
            }
        }
        return T;
        

    }
}; 

//
//int main() {
//    Solution S;
//    vector<int> T = S.partitionLabels("ababcbacadefegdehijhklij");
//    for (vector<int>::iterator i = T.begin(); i != T.end(); i++) {
//        cout << *i << endl;
//    }
//}